import java.rmi.server.ObjID;
import java.util.PriorityQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class Student {
    private static String classRoom = "abc";

    public static String getClassRoom() {
        return classRoom;
    }
}

class MyTimeTask {
    private Runnable runnable;
    private long time;

    public MyTimeTask(Runnable runnable,long delay) {
        this.runnable = runnable;
        this.time = System.currentTimeMillis() + delay;
    }

    public void run() {
        runnable.run();
    }

    public long getTime() {
        return time;
    }
}

class Mytimer {
    private PriorityQueue<MyTimeTask> taskQueue = new PriorityQueue<>();
    private Object locker = new Object();

    public Mytimer() {
        try
        {
            while(true) {
                synchronized(locker) {
                    if(taskQueue.size() == 0) {
                        locker.wait();
                    }

                    MyTimeTask task = taskQueue.peek();
                    long currentTime = System.currentTimeMillis();
                    if(currentTime >= task.getTime()) {
                        task.run();
                        taskQueue.poll();
                    } else {
                        // 时间没到，进行阻塞
                        locker.wait(task.getTime() - currentTime);
                    }
                } 
            }
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }

    public void schedule(Runnable runnable,long delay) {
        synchronized(locker) {
            MyTimeTask task = new MyTimeTask(runnable, delay);
            taskQueue.offer(task);
            locker.notify();
        }
    }

}

public class demo1 {
    public static void main(String[] args) {
        Student student = new Student();
        System.out.println(student.getClassRoom());
    }
    public static void main1(String[] args) {
        // 创建一个最普通的线程池
        // 能够根据任务的数目，自动进行扩容
        ExecutorService service = Executors.newCachedThreadPool();

        service.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello " + Thread.currentThread().getName());
            }
        });

        // 创建固定线程数目的线程池
//        Executors.newFixedThreadPool(4);
//        // 创建一个只包含单个线程的线程池
//        Executors.newSingleThreadExecutor();
//        // 创建一个固定线程个数， 但是任务延迟时执行的线程池
//        Executors.newScheduledThreadPool(4);
    }
}